package logic

import (
	"context"
	"zkzk2/models/mysql"

	"zkzk2/zk2rpc/internal/svc"
	"zkzk2/zk2rpc/zk2rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *zk2rpc.AddRequest) (*zk2rpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	Add := mysql.User{
		Tel:      in.Tel,
		Password: in.Password,
		Age:      in.Age,
		Email:    in.Email,
		Img:      in.Img,
	}

	mysql.DB.Debug().Model(&Add).Create(&Add)

	return &zk2rpc.AddResponse{Id: int64(Add.ID)}, nil
}
